﻿
namespace RealidadeAumentada.Entidades
{
    public class EPontoInteiro2D
    {
        public int x;
        public int y;

        #region Setar Valor
        public void SetarValor(EPontoInteiro2D i_source)
        {
            this.x = i_source.x;
            this.y = i_source.y;
        }

        public void SetarValor(EPontoDuplo2D i_source)
        {
            this.x = (int)i_source.x;
            this.y = (int)i_source.y;
        }

        public void SetarValor(int i_x, int i_y)
        {
            this.x = i_x;
            this.y = i_y;
        }
        #endregion

        #region Array
        public static EPontoInteiro2D[] CriarArray(int i_number)
        {
            EPontoInteiro2D[] ret = new EPontoInteiro2D[i_number];
            for (int i = 0; i < i_number; i++)
            {
                ret[i] = new EPontoInteiro2D();
            }
            return ret;
        }

        public static void CopiarArray(EPontoInteiro2D[] i_from, EPontoInteiro2D[] i_to)
        {
            for (int i = i_from.Length - 1; i >= 0; i--)
            {
                i_to[i].x = i_from[i].x;
                i_to[i].y = i_from[i].y;
            }
            return;
        }
        #endregion

        #region Distância do Quadrado
        public int DistanciaQuadrado(EPontoInteiro2D i_p1)
        {
            int x = this.x - i_p1.x;
            int y = this.y - i_p1.y;
            return x * x + y * y;
        }
        #endregion

        #region Centralizar
        public void Centralizar(EPontoInteiro2D[] i_point, int i_number_of_vertex)
        {
            int cx, cy;
            cx = cy = 0;
            for (int i = i_number_of_vertex - 1; i >= 0; i--)
            {
                cx += i_point[i].x;
                cy += i_point[i].y;
            }
            this.x = cx / i_number_of_vertex;
            this.y = cy / i_number_of_vertex;
        }
        #endregion
    }
}
